/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Project: javase - Dir6
 * <p>Powered by webrx On 2021-12-13 19:24:48
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Dir6 {
    static Map<String, Integer> map = new HashMap<>();

    public static void main(String[] args) {
        count(new File("c:/javase"));
        System.out.println(map);
    }

    public static void count(File src) {
        for (File f : src.listFiles()) {
            if (f.isDirectory()) {
                count(f);
            } else {
                String fn = f.getName().toLowerCase();
                String ext = fn.lastIndexOf(".") == -1 ? "unknow" : fn.substring(fn.lastIndexOf("."));
                if (map.containsKey(ext)) {
                    map.put(ext, map.get(ext) + 1);
                } else {
                    map.put(ext, 1);
                }
            }
        }
    }

    public static void test(String[] args) {
        var path = "d:/ccccc";
        var f = new File(path);
        if (!f.exists()) f.mkdirs();
    }
}
